<template>
<view class="container">
    <scroll-view class="scrollList" scroll-y="true" bindscrolltolower="onListReachBottom" :style="'height:' + main_height + 'px;'"> 
        <block v-for="(item, store_list) in store_list" :key="store_list">
            <view class="dealcard bw" @tap="goOrderDetail" :data-order_id="item.order_id">
                <view class="fl img">
                    <image :src="item.image"></image>
                </view>
                <view class="text">
                    <view class="h2">{{item.name}}</view>
                    <view class="clearfix list_p">
                        <view class="p fl"><lang keywords="订单号"></lang>：{{item.order_id}}</view>
                        <view class="p fl"><lang keywords="总价"></lang>：￥{{item.total_price}}</view>
                        <block v-if="item.discount_price > 0">
                            <view class="p fl red"><lang keywords="优惠"></lang>：￥{{item.discount_price}}</view>
                        </block>
                        <view class="p fl green"><lang keywords="实付"></lang>：￥{{item.price}}</view>
                        <view class="p fl time"><lang keywords="买单时间"></lang>：{{item.pay_time}}</view>
                    </view>
                </view>
            </view>
        </block>
    </scroll-view>
</view>

</template>

"<script>
import common from '../../utils/common.js'
var sysRes = {};
var app = getApp();

export default {
  data() {
    return {
      mer_id: 0,
      order_id: 0,
      store_list: [],
      main_height: 0
    };
  },

  onUnload: function () {// 页面关闭
  },
  onHide: function () {// 页面隐藏
  },
  onShow: function () {// 页面显示
  // #ifdef H5
  common.hideWxShare()
  // #endif
  },
  onReady: function () {// 页面渲染完成
  },
  onLoad: function (options) {
    if (!options.mer_id && app.merchantOwn) {
      options.mer_id = app.merchantOwn.mer_id;
    }

    if (options.mer_id) {
      this.setData({
        mer_id: options.mer_id
      });
    } // 页面初始化 options为页面跳转所带来的参数


    sysRes = wx.getSystemInfoSync();
    this.setData({
      main_height: sysRes.windowHeight
    });

    if (!app.globalData.userInfo) {
      var that = this; //调用应用实例的方法获取全局数据

      common.getUserInfo(function (userInfo) {
        that.setMainContent();
      }, 'setting');
    } else {
      this.setMainContent();
    }
  },
  components: {},
  props: {},
  methods: {
    onListReachBottom: function () {
      if (this.order_id == 0) {
        return false;
      }

      if (this.store_list.length > 0) {
        common.post('My&a=store_order_list', {
          order_id: this.order_id,
          mer_id: this.mer_id
        }, "setOneContent", this);
      }
    },
    setOneContent: function (result) {
      console.log(result);
      this.setData({
        store_list: this.store_list.concat(result.list),
        order_id: result.order_id
      });
      wx.hideToast();
    },
    goOrderDetail: function (e) {
      wx.navigateTo({
        url: "store_order_detail?order_id=" + e.currentTarget.dataset.order_id
      });
    },
    setMainContent: function () {
      common.post('My&a=store_order_list', {
        mer_id: this.mer_id
      }, "setOneContent", this);
    },
    setData: function (obj) {
      let that = this;
      let keys = [];
      let val, data;
      Object.keys(obj).forEach(function (key) {
        keys = key.split('.');
        val = obj[key];
        data = that.$data;
        keys.forEach(function (key2, index) {
          if (index + 1 == keys.length) {
            that.$set(data, key2, val);
          } else {
            if (!data[key2]) {
              that.$set(data, key2, {});
            }
          }

          data = data[key2];
        });
      });
    }
  }
};
</script>
<style>
/* pages/my/store_order.css */
.dealcard{ padding: 20rpx; border-bottom: #f1f1f1 2rpx solid;}
.dealcard .img{ width: 180rpx; height: 120rpx;margin-top:16rpx;}
.dealcard .img image{ width: 100%; height: 100%;}
.dealcard .text{ margin-left: 200rpx; line-height: 1.3;}
.dealcard .text .h2{ font-size: 28rpx; padding-bottom: 10rpx;}
.dealcard .text .p{ font-size: 24rpx; color: #666; width: 50%;line-height:1.6}
.dealcard .text .p.time{ width: 100%;}
.dealcard .text .p.red{color: red; }
.dealcard .text .p.green{ color: green;}
</style>